<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="or ? 'exit-fullscreen' : 'fullscreen'" class="fullscreen" @click="fullSuccessFn" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      or: false
    }
  },
  created() {
    this.watchFn()
  },
  destroyed() {
    this.closewatchFn()
  },

  methods: {
    fullSuccessFn() {
      if (screenfull.isEnabled) {
        screenfull.toggle()
      }
    },
    watchFn() {
      if (screenfull.isEnabled) {
        screenfull.on('change', () => {
          this.or = screenfull.isFullscreen
        })
      }
    },
    closewatchFn() {
      if (screenfull.isEnabled) {
        screenfull.off('change')
      }
    }
  }

}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
